﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WordGame.Question;

namespace WordGame.Answer
{
    public class Libby : IWordGame
    {
        public int getCheater(string[] first, string[] second, string[] third)
        {
            if (first.Length == 1 && first[0] == "")
            {
                if(second.Length==1&& second[0]!="")
                {
                    if (third.Length == 0)
                    {
                        return -1;
                    }
                }
            }


            for (int i = 0; i < second.Length;i++ )
            {
                if (i > 0)
                {
                    if (first[i].IndexOf(third[i - 1]) == -1)
                    {
                        return 1;
                    }

                    if (first[i].Length + 2 == third[i].Length)
                    {
                        if ((third[i].IndexOf(second[i]) != -1) && second[i].IndexOf(first[i]) != -1)
                        {
                            continue;
                        }
                        else if (second[i].IndexOf(first[i]) == -1)
                        {
                            return 3;
                        }
                        else if (third[i].IndexOf(second[i]) == -1)
                        {
                            return 2;
                        }
                    }
                    else if (first[i].Length - third[i - 1].Length < 1)
                    {
                        return 1;
                    }
                    else if (second[i].Length - first[i].Length != 1)
                    {
                        return 2;
                    }
                    else if (third[i].Length - second[i].Length != 1)
                    {
                        return 3;
                    }

                }
                else
                {
                    if (first[i].Length + 2 == third[i].Length)
                    {
                        if ((third[i].IndexOf(second[i]) != -1) && second[i].IndexOf(first[i]) != -1)
                        {
                            continue;
                        }
                        else if (second[i].IndexOf(first[i]) == -1)
                        {
                            return 3;
                        }
                        else if (third[i].IndexOf(second[i]) == -1)
                        {
                            return 2;
                        }
                    }
                    else if (second[i].Length - first[i].Length != 1)
                    {
                        return 2;
                    }
                    else if (third[i].Length - second[i].Length != 1)
                    {
                        return 3;
                    } 
                }
            }
            return -1;
        }

    }
}
